//+-----------------------------------------------
//+ axios封装  请求拦截、相应拦截、错误统一处理
//+-----------------------------------------------
//+ author:大明
//+-----------------------------------------------
//+ email:3228985941@qq.com
//+-----------------------------------------------

const httprequest = axios.create({
  baseURL: "http://localhost:5000",
  //timeout: 1000,
});

// 请求拦截器
httprequest.interceptors.request.use(
  function (config) {
    // 为请求添加token
    config.headers.token = '6666666666666'
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);

//响应拦截
httprequest.interceptors.response.use(
  function (response) {
    const res = response.data;
    //跳转到登录页
    if (res.code === 401) {
      window.location = `${window.logoutUrl}?url=${window.location.origin}`;
    }
    return res;
  },
  function (error) {
    return Promise.reject(error);
  }
);

// 封装get请求
function get(url, params) {
  return httprequest.get(url, { params: params })
}
// 封装post请求 qs.stringify(data)
function post(url, data) {
  return httprequest.post(url, Qs.stringify(data))
}



//+-----------------------------------------------
//+ 统一定义请求接口方便管理
//+-----------------------------------------------
//+ author:大明
//+-----------------------------------------------
//+ email:3228985941@qq.com
//+-----------------------------------------------

/**
 * 获取文件列表
 * @param {*} params 
 * @returns 
 */
function getFileList(params) {
  return httprequest({
    url: '/fileList',
    method: 'get',
    params: params,
  })
}

/**
 * 合并文件
 * @param {*} params 
 * @returns 
 */
function merge(params) {
  return httprequest({
    url: '/merge',
    method: 'get',
    params: params,
  })
}

/**
 * 上传接口
 * @param {*} data 
 * @returns 
 */
function uploadFile(data) {
  return httprequest({
    url: '/upload',
    method: 'post',
    data: data,
  })
}

/**
 * 检查文件
 * @param {} params 
 * @returns 
 */
function checkFile(params) {
  return httprequest({
    url: '/check/file',
    method: 'get',
    params: params,
  })
}

/**
 * 删除文件
 * @param {*} params 
 * @returns 
 */
function delFile(params) {
  return httprequest({
    url: '/delFile',
    method: 'get',
    params: params,
  })
}